/*
 *说明：授权情况审计
 *
 *@author liuxun 2012-03-06
*/

var opeForm;
var grid;

$(function(){
	opeForm = $('#opeForm');

	grid=$('#listTable').datagrid({
		frozenColumns:[[
            //{title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[

            {title:'授权人',field:'AUTH_NAME',align:'center',width:80},

            {title:'授权时间',field:'AUTH_TIME',align:'center',width:120},
            
            {title:'授权对象',field:'AUTH_OBJ',align:'center',width:80},
            
            {title:'所属机构',field:'ORG_NAME',align:'center',width:120},
            
            {title:'节点名称',field:'NODE_DECODE',align:'center',width:80},
            
            {title:'资源组',field:'RSC_GRP',align:'center',width:80},
            
            {title:'资源名称',field:'RSC_NAME',align:'center',width:80},
            
            {title:'管理IP',field:'MANAGE_IP',align:'center',width:100},
            
            {title:'服务IP',field:'SERVICE_IP',align:'center',width:100},
            
            {title:'账号名',field:'RSC_ACC_NAME',align:'center',width:80},
            
            {title:'端口',field:'PRO_PORT',align:'center',width:60},
            
            {title:'状态',field:'ACL_STATUS',align:'center',width:40,
            	formatter:function(value,rec){
            		if(value == '01'){
            			return '激活';
            		}else if(value == '02'){
            			return "<font color='red'>失效</font>";
            		}else if(value = '03'){
            			return "<font color='red'>删除</font>";
            		}else{
            			return '';
            		}
			    }
            },
            
            {title:'长期有效',field:'IS_LONGTERM_VALID',align:'center',width:60,
            	formatter:function(value,rec){
            		return value ==  '1' ? '<font color="green"> √ </font>' : '<font color="red"></font>';
  			    }	
            },
            
            {title:'开始时间',field:'START_TIME',align:'center',width:110},
            
            {title:'有效期(分钟)',field:'AVAILABLE_LENGTH',align:'center',width:80}
        ]]
	});

	queryOperation();

	$('#queryBtn').click(queryOperation);
	$('#clearBtn').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
	$('#genReportBtn').click(genReporOperation);
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		url: 'AUDIT_REPORT!queryAuthList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//生成授权情况审计报表
function genReporOperation(){  
	opeForm.attr('action', 'AUDIT_REPORT!genAuthAuditReport.do');
	opeForm.submit();
}

//选择资源组
function select_a_usr() {
	var action = "A_USR!showSelect.do";
	var row = showModalWin(action,'A2');
	
	if (row) {
		$('#auth_person_id').val(row.usr_id);
		$('#auth_person_name').val(row.usr_name);
	}
}

//选择授权对象
function select_auth_obj_id() {
	var action = "A_USR!showSelect.do";
	var row = showModalWin(action,'A2');
	
	if (row) {
		$('#auth_obj_id').val(row.usr_id);
		$('#auth_obj_name').val(row.usr_name);
	}
}

//选择资源
function select_c_rsc() {
	var action = "C_RSC!showSelect.do";
	var row = showModalWin(action,'A2');
	
	if (row) {
		$('#rsc_id').val(row.rsc_id);
		$('#rsc_name').val(row.rsc_name);
	}
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}